package com.voole.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.voole.entity.SysAuthority;
import com.voole.entity.SysCatalog;
import com.voole.entity.SysResource;

@Repository
public interface SysCatalogDao {

	@Select(value="SELECT * FROM sys_catalog ORDER BY sort")
	List<SysCatalog> getList();
	
	@Select(value="SELECT * FROM sys_catalog WHERE authorityid = #{param} ORDER BY sort")
	List<SysCatalog> getListByAuthorithId(@Param(value="param")Integer authorityId);
	
	@Select(value="SELECT DISTINCT(sc.id) FROM sys_resource sr LEFT JOIN sys_catalog sc ON sr.catalogid=sc.id WHERE sr.id IN (${resourceIds})")
	List<Integer> getColumnCatalogIdByResourceId(@Param(value="resourceIds")String resourceIds);
	
	@Select(value="SELECT * FROM sys_catalog WHERE id = ${param}")
	SysCatalog getSysCatalog(@Param(value="param")Integer catalogId);
	
	@Insert("INSERT INTO sys_catalog (`catalogname`, `authorityid`, `sort`, `status`) VALUES(#{catalogname}, #{authorityid}, #{sort}, #{status})")  
	@Options(useGeneratedKeys = true, keyProperty = "id")
	Integer addSysCatalog(SysCatalog sysCatalog);
	
	@Update("UPDATE sys_catalog SET catalogname = #{catalogname}, authorityid = #{authorityid}, sort = #{sort}, status = #{status} WHERE id = #{id}")  
	Integer updateSysCatalog(SysCatalog sysCatalog);
	
	@Delete(value="delete from sys_catalog where id = #{catalogId}")
	Integer delSysCatalog(Integer catalogId);
	
	@Delete(value="delete from sys_catalog where authorityid = #{authorityId}")
	Integer delListByAuthorithId(Integer authorityId);
}

